<?php

session_start();
include_once('db.php');

if (empty($_SESSION['email']) || empty($_SESSION['password'])) {
	header('location: login.php');
}

$email = mysql_real_escape_string($_SESSION['email']);
$password = mysql_real_escape_string($_SESSION['password']);
$type = fetch_only("SELECT `Type` FROM `USER` WHERE `Email`='$email'");
$type = $type['Type'];
$link = '<a href="dashboard.php">Dashboard</a>';

if ($type === 'A') {
	$link = '<a href="employee_management.php">Employee Management</a>';
}

function fetch_only($query) {
	$result = mysql_query($query);
	
	if (mysql_error()) {
		die(mysql_error());
	}
	
	return mysql_fetch_assoc($result);
}

function fetch_all($query) {
	$result = mysql_query($query);
	
	if (mysql_error()) {
		die(mysql_error());
	}
	
	$array = Array();
	
	while($row = mysql_fetch_assoc($result)) {
		array_push($array, $row);
	}
	
	return $array;
}

function run($query) {
	mysql_query($query);
	
	if (mysql_error()) {
		die(mysql_error());
	}
}

function format_date(&$mixed, $key, $format) {
	if (isset($mixed[$key])) {
		$mixed[$key] = date($format, strtotime($mixed[$key]));
	} else {
		for ($i = 0; $i < count($mixed); $i++) {
			$mixed[$i][$key] = date($format, strtotime($mixed[$i][$key]));
		}
	}
}

?>